#ifndef __BOARD_DESC_H_
#define __BOARD_DESC_H_

#include "type.h"

#define MCU_GPIO_GROUP_SIZE		16			//每个GPIO组内最多的GPIO数量
#define GPIO_VIRTUAL_ADDR(GROUP, PHYSICAL_ADDR)	((GROUP * MCU_GPIO_GROUP_SIZE + PHYSICAL_ADDR) & 0xff)


enum egpio_pin_name {
	BEEP_PIN = 0,
    LED_GREEN_PIN,     
	LED_RED_PIN, 
	KEY0_PIN,
	KEY1_PIN,
	KEY2_PIN,
	WAKE_UP_PIN,
	WS2812_DI,
	WS2812_OUT,
    
    GPIO_TOTAL_NUM,   
};
	
enum egpio_irq_src {
    KEY0_PIN_IRQ = 0,
	KEY1_PIN_IRQ,
	KEY2_PIN_IRQ,
	KEY3_PIN_IRQ,
	WAKE_UP_PIN_IRQ,
    
    MAX_IRQ_SOURCE,
};

enum egpio_dir {
	OUTPUT = 0,
	INPUT,
	AFMOD,
	ANMOD,
};

enum egpio_pupd {
	NO_PULL = 0,
	PULL_UP,
	PULL_DOWN,
};

enum egpio_level {
	GPIO_LOW = 0,
	GPIO_HIGH,
	INVALID_GPIO_NUM = 0xff,
};

enum eirq_type {
	NO_IRQ = 0,
	IRQ_FALLING,
	IRQ_RISING,
	IRQ_BOTH,
};

//ADC定义        
enum eadc_pin_name {
	BAT_ID_ADC = 0,
    NTC_ADC,

    ADC_TOTAL_NUM,
};

typedef struct {
    uint32_t pin_num;          //GPIO物理pin num
    uint32_t adc_channel;      //有效电平
    uint8_t port;             //port号
    uint8_t mode;             //采样模式：0单次；1连续
    uint32_t sampling_freq;   //采样频率
}ez_adc_dev_t;
//PWM定义 
enum pwm_index_name {    
    HEARTING_FILM_PWM = 0,
    
    PWM_TOTAL_INDEX,
};

typedef struct 
{
    uint8_t   gpio_num; 	//管脚序号
	//使用预分频和自动装载置配置的平台可以根据duty_cycle,freq计算
	uint16_t duty_cycle;    //duty_cycle range is 0~10000 correspond to 0~100%
	uint16_t freq; 		    //freq range is between 0~40MHZ	
	uint8_t port;           //port号
}ez_pwm_dev_t;


//I2C定义
typedef struct 
{
    uint8_t   scl_pin; 	        //SCL管脚序号
    uint8_t   sda_pin; 	        //SDA管脚序号
	uint32_t  freq; 		    //freq range is between 0~40MHZ
	uint8_t   port;             //port号
	uint8_t   address_width;    //地址宽度 1：7bit       2：10bit 
    uint8_t   mode;             //主从机模式      1：主机 2：从机
}ez_i2c_dev_t;

//TIMER定义
typedef struct 
{
    uint32_t          period;         //timer period, us
    uint8_t           reload_mode;    //是否自动重载
    uint8_t           port;           //port号
}ez_timer_dev_t;

enum egpio_multi {
	NOMULTI = 0,
	MULTI,
};

enum egpio_reconfig {
	NOT_RECONFIG = 0,
	RECONFIG,
};

typedef struct {
	uint8_t pin_name;	//中断引脚名
	uint8_t irq_src;	//中断源
}T_MCU_IRQ_MAPPING;

enum egpio_group {
	GROUP_GPIOA = 0,
	GROUP_GPIOB,
	GROUP_GPIOC,
	GROUP_GPIOD,
	GROUP_GPIOE,
	GROUP_GPIOF,
	GROUP_GPIOG,
	GROUP_GPIOH,
	GROUP_GPIOI,
	GROUP_MAX,
	GROUP_INVALID = 0xff,
};
	
typedef struct {
	unsigned char gpio_group;			//GPIO组
	unsigned char gpio_physical_pin;	//GPIO物理pin num
	unsigned char gpio_virtual_pin;		//GPIO虚拟pin num
	unsigned char gpio_active;			//有效电平
	unsigned char dir;					//输入输出方向
	unsigned char pupd;					//内部上下拉
	unsigned char irq_type;				//中断类型
	unsigned char is_multi;				//是否复用
	unsigned char is_support_reconfig;//是否支持重配置
}T_GPIO_INFO;




#endif